import cv2
from ultralytics import YOLO

# Load a YOLO11n PyTorch model
# model = YOLO("yolov8n.pt")
#
# Export the model to NCNN format
# model.export(format="openvino")  # creates 'yolo11n_ncnn_model'

def detect_traffic_light2(frame):
    # Load the exported NCNN model
    openvino_model = YOLO("lib/yolov8n_openvino_model/")


        # Run inference on the frame
    results = openvino_model(frame)

    # Draw the results on the frame
    for box in results[0].boxes:
        bbox = box.xyxy[0].tolist()  # Get the bounding box coordinates
        if int(box.cls[0]) == 9:
            return True
                #label = results[0].names[int(box.cls[0])]  # Get the label

                # cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (0, 255, 0), 2)
                # cv2.putText(frame, label, (int(bbox[0]), int(bbox[1]) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)

        # Display the frame
        # cv2.imshow('YOLO Video Detection', frame)

        # Press 'q' to exit the video
        # if cv2.waitKey(1) & 0xFF == ord('q'):
        #    break


    # Release the video capture object and close all OpenCV windows

    return False
    # cv2.destroyAllWindows()
